Passed
Push — development ( 2f9cbb...cdc56b )
by Peter
09:24 queued 15s
created

Map.tsx ➔ Map   A

Complexity

Conditions 2

Size

Total Lines 32
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 29
dl 0
loc 32
ccs 6
cts 6
cp 1
crap 2
rs 9.184
c 0
b 0
f 0
1
import { MapContainer, TileLayer} from 'react-leaflet';
2
import { useEffect, useState } from 'react';
3
import { LatLngExpression } from 'leaflet';
4
import { Scooter,  Zone } from '../helpers/map/leaflet-types'
5
import { cities } from '../helpers/map/cities';
6
import MapCenter from './MapCenter';
7
import { renderScooterMarkers, renderPolygons } from '../helpers/map/renders';
8
9
type propTypes = {
10
    city: string;
11
    zoneData: Zone[];
12
    scooterData: Scooter[]
13
}
14
15
export default function Map({city, zoneData, scooterData} : propTypes) {
16
17 4
    const [startPosition, setStartPosition] = useState<LatLngExpression>([-48.876667, -123.393333]);
18 4
    const zoom = 11;
19
20 4
    useEffect(() => {
21 4
        if (city && cities[city]) {
22 1
            setStartPosition(cities[city]);
23
        }
24
    }, [city, zoneData, scooterData]);
25
    
26 4
  return (
27
    <div id="map-container">
28
            <div id="map" data-testid="map">
29
                <MapContainer
30
                    style={{ height: "400px" }}
31
                    center={startPosition}
32
                    zoom={zoom}
33
                    scrollWheelZoom={true}
34
                >
35
                    <TileLayer
36
                        attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
37
                        url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
38
                    />
39
                    <MapCenter center={startPosition} zoom={zoom} />
40
                    {renderScooterMarkers(scooterData)}
41
                    {renderPolygons(zoneData)}
42
                </MapContainer>
43
            </div>
44
           
45
        </div>
46
  )
47
};
48